package parser;

import antlr.RecognitionException;
import antlr.Token;
import java.util.List;

class MemberExpr extends Expr {
    
    Expr expr;
    int name;
    
    MemberExpr(Expr expr, int name) {
        this.name = name;
        this.expr = expr;
    }
    
    void write(ByteStream out) throws RecognitionException {
        expr.write(out);
        out.write(Opcodes.LOAD_ATTR);
        out.writeShort(name);
    }
    
    void writeLHS(ByteStream out) throws RecognitionException {
        expr.write(out);
        out.write(Opcodes.STORE_ATTR);
        out.writeShort(name);
    }
    
    void delete(ByteStream out) throws RecognitionException {
        expr.write(out);
        out.write(Opcodes.DELETE_ATTR);
        out.writeShort(name);
    }
    
    void writeAugAsgn(int op, Expr value, ByteStream out) throws RecognitionException {
        expr.write(out);   //  e
        out.write(Opcodes.COPY); // e e 
        out.write(Opcodes.LOAD_ATTR);
        out.writeShort(name);   // e e.name
        value.write(out);  // e e.name v
        out.write(Opcodes.INPLACE);
        out.write(op);  // e e.name+v
        out.write(Opcodes.SWAP); // e.name+v e
        out.write(Opcodes.STORE_ATTR);
        out.writeShort(name);
    }
}
